/**
 * 
 */
package com.hexacta.hrs.web.struts.actions.reports;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.vectrics.common.util.StringUtils;
import org.vectrics.employee.Employee;

import com.hexacta.hrs.services.employee.EmployeeService;
import com.hexacta.hrs.services.timeoff.TimeOffService;
import com.hexacta.hrs.timeoff.ObjectListTimeOffType;
import com.hexacta.hrs.timeoff.Status;
import com.hexacta.hrs.timeoff.TimeOffType;
import com.hexacta.hrs.web.struts.actions.BaseReportAction;

/**
 * @author mfunes
 *
 */
public class GeneralTimeOffReportAction extends BaseReportAction {

    private static final long serialVersionUID = -6198288352581466809L;
    private TimeOffService timeOffService;
    private EmployeeService employeeService;
    private String selectedEmployeeId;
    private String selectedStatus;
    private String selectedTimeOffType;
    private Date selectedDateFrom;
    private Date selectedDateTo;
    
    public TimeOffService getTimeOffService() {
        return timeOffService;
    }

    public void setTimeOffService(TimeOffService timeOffService) {
        this.timeOffService = timeOffService;
    }

    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    public void setEmployeeService(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public String getSelectedEmployeeId() {
        return selectedEmployeeId;
    }

    public void setSelectedEmployeeId(String selectedEmployeeId) {
        this.selectedEmployeeId = selectedEmployeeId;
    }

    public String getSelectedStatus() {
        return selectedStatus;
    }

    public void setSelectedStatus(String selectedStatus) {
        this.selectedStatus = selectedStatus;
    }

    public String getSelectedTimeOffType() {
        return selectedTimeOffType;
    }

    public void setSelectedTimeOffType(String selectedTimeOffType) {
        this.selectedTimeOffType = selectedTimeOffType;
    }

    public Date getSelectedDateFrom() {
        return selectedDateFrom;
    }

    public void setSelectedDateFrom(Date selectedDateFrom) {
        this.selectedDateFrom = selectedDateFrom;
    }

    public Date getSelectedDateTo() {
        return selectedDateTo;
    }

    public void setSelectedDateTo(Date selectedDateTo) {
        this.selectedDateTo = selectedDateTo;
    }

    public Collection<Employee> getEmployeeList() {
        return employeeService.getAll();
    }
    
    public List<ObjectListTimeOffType> getAllTimeOffTypes() {
    	List<ObjectListTimeOffType> timeOffTypeList = new ArrayList<ObjectListTimeOffType>();
    	
    	TimeOffType[] timeOffTypesEnum = TimeOffType.values();
    	for (int i = 0; i < timeOffTypesEnum.length; i++) {
    		ObjectListTimeOffType timeOffType = new ObjectListTimeOffType();
    		String name = timeOffTypesEnum[i].name();
    		timeOffType.setId(name);
    		name = name.replaceAll("_", " ");
    		timeOffType.setName(name);
    		timeOffTypeList.add(timeOffType);
		}
    	
        return timeOffTypeList;
    }
    
    public List<Status> getAllStatuses() {
        return Arrays.asList(Status.values());
    }
    
    @Override
    protected Map<String, Object> getReportFilters() {
        Map<String, Object> filters = new HashMap<String, Object>();
        if (filters == null){
          filters = new HashMap<String, Object>();
        }
        if(selectedDateFrom != null){
            filters.put("selectedDateFrom", selectedDateFrom);
        }
        if(selectedDateTo != null){
            filters.put("selectedDateTo", selectedDateTo);
        }
        if(!StringUtils.isNullOrBlank(selectedEmployeeId)){
            filters.put("selectedEmployeeId", selectedEmployeeId);
        }
        if(!StringUtils.isNullOrBlank(selectedStatus)){
            filters.put("selectedStatus", selectedStatus);
        }
        if(!StringUtils.isNullOrBlank(selectedTimeOffType)){
            filters.put("selectedTimeOffType", selectedTimeOffType);
        }
            
        return filters;
    }

}
